package com.microservice.consumer.movie.service.feignfactory;

import com.microservice.consumer.movie.bean.User;
import com.microservice.consumer.movie.service.UserFeignInterface;
import feign.hystrix.FallbackFactory;
import lombok.extern.java.Log;
import org.springframework.stereotype.Component;

import java.util.Map;

@Log
@Component
public class UserFeignFactory implements FallbackFactory<UserFeignInterface> {
    @Override
    public UserFeignInterface create(Throwable throwable) {
        return new UserFeignInterface() {
            @Override
            public User findById(Long id) {
                User user = new User();
                user.setName("[findById]:"+throwable.getCause());
                user.setId(-1L);
                if(throwable instanceof IllegalArgumentException){
                    user.setId(-2L);
                }
                log.info(throwable.toString());
                log.info("断路器："+user.getName());
                return user;
            }

            @Override
            public User findByMap(Map id) {

                return null;
            }
        };
    }
}
